<?php

namespace App\Logic;

use \Common\Logic\BaseLogic;

class AdLogic extends BaseLogic
{
    private $adModel;
    static $field = "id,cover,url";

    public function __construct()
    {
        parent::__construct();
        $this->adModel = D('Ad');
    }

    /**
     * 获取任务列表轮播广告
     * @return mixed
     */
    public function getTaskIndexBannerAd()
    {
        return $this->get(2, 5);
    }
    
    public function getHomeIndexBannerAd(){
        return $this->get(1, 5);
    }


    /**
     * 获取广告
     * @param int $type
     * @param int $size
     * @return mixed
     */
    public function get($type = 1, $size = 1)
    {
        $where = array(
            "ad_type" => $type,
            "state" => 1
        );

        $list = $this->adModel->field(static::$field)->where($where)
            ->order("sort desc,id desc")->limit("0," . $size)->select();
        return $list;
    }


}
